home *** CD-ROM | disk | FTP | other *** search
- #include <abc.h>
-
- #include <MacTypes.h>
- #include <Quickdraw.h>
- #include <WindowMgr.h>
- #include <EventMgr.h>
- #include <MenuMgr.h>
- #include <DeskMgr.h>
- #include <ScrapMgr.h>
-
- #define AppleID 30
- #define FileID 31
- #define EditID 32
-
- MenuHandle appleMenu,
- fileMenu,
- editMenu;
- EventRecord theEvent;
- WindowPtr clipWindow;
-
- short scrapCompare;
- char theString[256];
- Boolean done;
-
- main()
- {
- initialize();
- doEvents();
- } /* main */
-
- initialize()
- {
- Rect wRect;
-
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( NULL );
- InitCursor();
-
- FlushEvents ( everyEvent, 0 );
- setUpMenus();
-
- SetRect ( &wRect, 60, 50, 450, 250 );
- clipWindow = NewWindow( NULL, &wRect, "\PClipboard",
- TRUE, 0, -1L, FALSE, NULL );
-
- /* force an initial update of the Clipboard window */
- scrapCompare = InfoScrap()->scrapCount + 1;
-
- done = FALSE;
-
- } /* initialize */
-
- setUpMenus()
- {
- appleMenu = NewMenu ( AppleID, "\P\024" );
- AddResMenu ( appleMenu, 'DRVR');
- InsertMenu ( appleMenu, 0 );
-
- fileMenu = NewMenu ( FileID, "\PFile" );
- AppendMenu ( fileMenu, "\PQuit" );
- InsertMenu ( fileMenu, 0 );
-
- editMenu = NewMenu ( EditID, "\PEdit" );
- AppendMenu ( editMenu, "\PUndo;(-;Cut;Copy;Paste;Clear" );
- InsertMenu ( editMenu, 0 );
-
- DrawMenuBar();
-
- } /* setUpMenus */
-
- doEvents()
- {
- WindowPtr wWindow;
- GrafPtr savePort;
- INTEGER thePart;
-
- done = FALSE;
- do {
-
- /* check to see if the scrap has changed recently… */
- if ( scrapCompare NEQ InfoScrap()->scrapCount ) {
- GetPort ( &savePort );
- SetPort ( clipWindow );
- InvalRect ( &clipWindow->portRect );
- SetPort ( savePort );
- scrapCompare = InfoScrap()->scrapCount;
- }
-
- if ( GetNextEvent ( everyEvent, &theEvent ) ) {
- switch ( theEvent.what ) {
- case mouseDown:
- thePart = FindWindow ( theEvent.where, &wWindow );
- switch ( thePart ) {
- case inContent:
- if ( FrontWindow() NEQ wWindow )
- SelectWindow ( wWindow );
- break;
- case inMenuBar:
- doMenuClick();
- break;
- case inSysWindow:
- SystemClick ( &theEvent, wWindow );
- break;
- default:
- SysBeep ( 2 );
- break;
- } /* switch thePart */
- break;
- case keyDown:
- done = TRUE;
- break;
- case updateEvt:
- if ( (WindowPtr) theEvent.message EQ clipWindow )
- updateClipWindow ( clipWindow );
- break;
- case activateEvt:
- if ( (WindowPtr) theEvent.message EQ clipWindow ) {
- SetPort ( theEvent.message );
- if ( theEvent.modifiers bAND activeFlag )
- DisableItem ( editMenu, 0 );
- else
- EnableItem ( editMenu, 0 );
- }
- break;
- } /* switch theEvent.what */
- } /* if GNE */
- } while ( NOT done );
- } /* doEvents */
-
- doMenuClick()
- {
- long menuChoice;
-
- menuChoice = MenuSelect ( theEvent.where );
- doMenuChoice ( menuChoice );
-
- } /* doMenuClick */
-
- doMenuChoice( theMenu, theItem )
- short theMenu, theItem;
- {
- short accNumber;
-
- switch ( theMenu ) {
- case AppleID:
- GetItem ( appleMenu, theItem, theString );
- accNumber = OpenDeskAcc ( theString );
- break;
- case FileID:
- if ( theItem EQ 1 )
- done = TRUE;
- break;
- case EditID:
- if ( NOT SystemEdit ( theItem - 1) )
- SysBeep ( 2 );
- break;
- default:
- break;
- } /* switch */
-
- HiliteMenu ( 0 );
-
- } /* doMenuChoice */
-
- updateClipWindow ( badWindow )
- WindowPtr badWindow;
- {
- GrafPtr savePort;
- Rect dispRect;
- Handle theHandle;
- long offset,
- theSize;
-
- theHandle = NewHandle ( 8L );
-
- GetPort ( &savePort );
- SetPort ( badWindow );
- BeginUpdate ( badWindow );
- EraseRect ( &badWindow->portRect );
-
- dispRect = badWindow->portRect;
- InsetRect ( &dispRect, 5, 5 );
-
- if ( (theSize = GetScrap ( theHandle,
- 'TEXT', &offset )) > 0 ) {
- HLock ( theHandle );
- myTextBox ( badWindow, &dispRect,
- *theHandle, theSize );
- HUnlock ( theHandle );
- } else if ( (theSize = GetScrap ( theHandle,
- 'PICT', &offset )) > 0 ) {
- drawAPicture ( badWindow, &dispRect,
- theHandle );
- }
- EndUpdate ( badWindow );
-
- DisposHandle ( theHandle );
-
- } /* updateClipWindow */
-
- myTextBox ( textWindow, textRect, textPtr, textLength )
- WindowPtr textWindow;
- Rect *textRect;
- register char textPtr[];
- long textLength;
- {
- register long index;
-
- FontInfo theFontInfo;
- short textHeight,
- boxWidth, boxHeight,
- theHeight, strLength;
- long startLine, canBreak;
-
- TextFont ( 3 ); /* Geneva */
- TextSize ( 12 ); /* 12 point */
- TextFace ( 0 ); /* Plain Text */
-
- GetFontInfo ( &theFontInfo );
- textHeight = theFontInfo.ascent + theFontInfo.descent
- + theFontInfo.leading;
-
- boxWidth = textRect->right - textRect->left;
- boxHeight = textRect->bottom - textRect->top;
-
- theHeight = textRect->top - theFontInfo.descent;
- strLength = 0;
- startLine = canBreak = -1;
-
- for ( index = 0; index < textLength AND theHeight < boxHeight; index++ ) {
- if ( textPtr[index] EQ CR ) /* if current char is a CR… */ {
- theHeight += textHeight;
- MoveTo ( textRect->left, theHeight );
- DrawText ( textPtr, startLine+1,
- index-startLine-1 );
- strLength = 0;
- startLine = canBreak = index;
- } else /* check for word wrap */ {
- strLength += CharWidth ( textPtr[index] );
- if ( strLength > boxWidth ) {
- if ( canBreak > startLine )
- index = canBreak;
- else
- index--;
-
- theHeight += textHeight;
- MoveTo ( textRect->left, theHeight );
- DrawText ( textPtr, startLine+1,
- index-startLine-1 );
- strLength = 0;
- startLine = canBreak = index;
- } else if ( textPtr[index] EQ ' ' OR
- textPtr[index] EQ TAB )
- canBreak = index;
- }
- } /* for index loop */
-
- theHeight += textHeight;
- MoveTo ( textRect->left, theHeight );
- DrawText ( textPtr, (short) (startLine+1), (short) (index-startLine-1) );
-
- } /* myTextBox */
-
- drawAPicture ( textWindow, dispRect, thePicture )
- WindowPtr textWindow;
- Rect *dispRect;
- PicHandle thePicture;
- {
- Rect drawRect;
-
- drawRect = (*thePicture)->picFrame;
- OffsetRect ( &drawRect, - drawRect.left + dispRect->left,
- - drawRect.top + dispRect->top );
- DrawPicture ( thePicture, &drawRect );
- } /* drawAPicture */
-
- drawACenteredPicture ( textWindow, dispRect, thePicture )
- WindowPtr textWindow;
- Rect *dispRect;
- PicHandle thePicture;
- {
- Rect drawRect;
- short hMove, vMove;
-
- drawRect = (*thePicture)->picFrame;
- hMove = dispRect->left - drawRect.left;
- hMove += dispRect->right - drawRect.right;
- hMove /= 2;
- vMove = dispRect->top - drawRect.top;
- vMove += dispRect->bottom - drawRect.bottom;
- vMove /= 2;
- OffsetRect ( &drawRect, hMove, vMove );
- DrawPicture ( thePicture, &drawRect );
- } /* drawACenteredPicture */
-
-